package com.tank.demo.game.model.base;


import com.tank.demo.game.constant.ObjImage;

import java.awt.*;

/**
 * 坦克大战中所有物体的基类
 */
public abstract class ObjectBase {

    /**
     * 横坐标
     */
    private int x;

    /**
     * 纵坐标
     */
    private int y;

    /**
     * 长度
     */
    private int width;


    /**
     * 宽度
     */
    private int height;

    /**
     * 图片
     */
    private ObjImage image;

    /**
     * 是否可见
     */
    private boolean visible;


    /**
     * 碰撞检测
     *
     * @return true:撞到了 false:没有撞到
     */
    public boolean impactChecking(ObjectBase obj) {
        return getSelfRectangle().intersects(obj.getSelfRectangle());
    }

    /**
     * 获取自己的区域
     *
     * @return
     */
    public Rectangle getSelfRectangle() {
        return new Rectangle(x, y, width, height);
    }

    public int getX() {
        return x;
    }

    public void setX(int x) {
        this.x = x;
    }

    public int getY() {
        return y;
    }

    public void setY(int y) {
        this.y = y;
    }

    public int getWidth() {
        return width;
    }

    public void setWidth(int width) {
        this.width = width;
    }

    public int getHeight() {
        return height;
    }

    public void setHeight(int height) {
        this.height = height;
    }

    public ObjImage getImage() {
        return image;
    }

    public void setImage(ObjImage image) {
        this.image = image;
    }

    public boolean isVisible() {
        return visible;
    }

    public void setVisible(boolean visible) {
        this.visible = visible;
    }
}
